<template>
  <div class="diagnosis-page">
    <div class="page-header">
      <h1 class="page-title">设备诊断</h1>
      <div class="page-actions">
        <el-button type="primary" icon="el-icon-plus">新建诊断</el-button>
        <el-button icon="el-icon-download">导出报告</el-button>
      </div>
    </div>
    
    <div class="expert-mode">
      <div class="status-tabs">
        <div class="status-tab" 
             @click="activeTab = 'status'" 
             :class="{ active: activeTab === 'status' }">设备状态概览</div>
        <div class="status-tab" 
             @click="activeTab = 'logs'" 
             :class="{ active: activeTab === 'logs' }">日志查询面板</div>
        <div class="status-tab" 
             @click="activeTab = 'map'" 
             :class="{ active: activeTab === 'map' }">指令控制面板</div>
        <div class="status-tab" 
             @click="activeTab = 'tools'" 
             :class="{ active: activeTab === 'tools' }">故障诊断辅助区</div>
      </div>
      
      <div class="status-content" v-if="activeTab === 'status'">
        <div class="status-card">
          <div class="status-title">服务器A123状态</div>
          <div class="status-details">
            <p>CPU使用率: 75%</p>
            <p>内存使用率: 60%</p>
            <p>磁盘使用率: 45%</p>
            <p>网络流量: 2.5Mbps</p>
            <p>最后更新: 2023-08-11 14:30:25</p>
            <p><el-tag type="success">正常</el-tag></p>
          </div>
        </div>
        
        <div class="status-card">
          <div class="status-title">交换机S789状态</div>
          <div class="status-details">
            <p>CPU使用率: 45%</p>
            <p>内存使用率: 30%</p>
            <p>磁盘使用率: 10%</p>
            <p>网络流量: 5.2Mbps</p>
            <p>最后更新: 2023-08-11 14:25:10</p>
            <p><el-tag type="warning">警告</el-tag></p>
          </div>
        </div>
      </div>
      
      <div class="status-content" v-if="activeTab === 'logs'">
        <div class="log-filters">
          <el-select v-model="logLevel" placeholder="日志级别">
            <el-option label="全部" value=""></el-option>
            <el-option label="信息" value="info"></el-option>
            <el-option label="警告" value="warning"></el-option>
            <el-option label="错误" value="error"></el-option>
          </el-select>
          <el-date-picker
            v-model="logDate"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
          <el-button type="primary" icon="el-icon-search">查询</el-button>
          <el-button icon="el-icon-refresh">重置</el-button>
        </div>
        
        <el-table :data="logs" border style="width: 100%">
          <el-table-column prop="time" label="时间"></el-table-column>
          <el-table-column label="级别">
            <template #default="scope">
              <div :class="['log-level', `level-${scope.row.level}`]" style="display: inline-block"></div>
              {{ scope.row.level }}
            </template>
          </el-table-column>
          <el-table-column prop="source" label="来源"></el-table-column>
          <el-table-column prop="content" label="内容"></el-table-column>
          <el-table-column label="操作">
            <template #default="scope">
              <el-button type="text" @click="showLogDetails(scope.row)">详情</el-button>
            </template>
          </el-table-column>
        </el-table>
        
        <div class="pagination">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="logs.length"
          ></el-pagination>
        </div>
      </div>
      
      <!-- 添加问题详情对话框 -->
      <el-dialog
        title="问题详情"
        v-model="logDetailsVisible"
        width="60%">
        <div class="log-details" v-if="currentLog">
          <div class="detail-item">
            <span class="detail-label">时间：</span>
            <span class="detail-value">{{ currentLog.time }}</span>
          </div>
          <div class="detail-item">
            <span class="detail-label">级别：</span>
            <span class="detail-value">{{ currentLog.level }}</span>
          </div>
          <div class="detail-item">
            <span class="detail-label">来源：</span>
            <span class="detail-value">{{ currentLog.source }}</span>
          </div>
          <div class="detail-item">
            <span class="detail-label">内容：</span>
            <span class="detail-value">{{ currentLog.content }}</span>
          </div>
          
          <!-- 快速回复模块 -->
          <div class="quick-reply-section">
            <h3>快速回复</h3>
            <div class="quick-reply-options">
              <el-button 
                v-for="(option, index) in quickReplyOptions" 
                :key="index"
                size="small" 
                @click="selectQuickReply(option)">
                {{ option.text }}
              </el-button>
            </div>
            <div class="custom-reply">
              <el-input
                type="textarea"
                :rows="3"
                placeholder="输入自定义回复..."
                v-model="customReply">
              </el-input>
              <el-button type="primary" @click="submitReply" style="margin-top: 10px;">
                提交回复
              </el-button>
            </div>
          </div>
        </div>
      </el-dialog>
      
      <div class="status-content" v-if="activeTab === 'map'">
        <div class="map-header">
          <div class="map-title">设备地图</div>
          <div class="map-actions">
            <el-button size="small">放大</el-button>
            <el-button size="small">缩小</el-button>
            <el-button size="small">重置</el-button>
          </div>
        </div>
        
        <div class="map-wrapper" ref="deviceMap"></div>
      </div>
      
      <div class="status-content" v-if="activeTab === 'tools'">
        <div class="tools-header">
          <div class="tools-title">诊断工具</div>
          <div class="tools-actions">
            <el-button type="primary">运行诊断</el-button>
          </div>
        </div>
        
        <div class="tools-grid">
          <div class="tool-card" v-for="(tool, index) in diagnosticTools" :key="index">
            <div class="tool-icon">{{ tool.icon }}</div>
            <div class="tool-name">{{ tool.name }}</div>
            <div class="tool-description">{{ tool.description }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// eslint-disable-next-line no-unused-vars
import L from 'leaflet'

export default {
  name: 'DiagnosisPage',
  data() {
    return {
      activeTab: 'status',
      logs: [
        { time: '2023-08-11 14:30:25', level: 'error', source: '服务器A123', content: 'CPU使用率超过90%' },
        { time: '2023-08-11 13:45:12', level: 'warning', source: '交换机B456', content: '网络延迟增加' },
        { time: '2023-08-11 12:30:05', level: 'info', source: '路由器C789', content: '系统自动更新完成' }
      ],
      currentPage: 1,
      pageSize: 10,
      logLevel: '',
      logDate: '',
      logDetailsVisible: false,
      currentLog: null,
      // 快速回复选项
      quickReplyOptions: [
        { text: '已收到您的问题，正在处理中', value: 'received' },
        { text: '请提供更多详细信息', value: 'more_info' },
        { text: '问题已解决，请确认', value: 'resolved' },
        { text: '我们将安排技术人员处理', value: 'tech_support' }
      ],
      customReply: ''
    }
  },
  methods: {
    handleSizeChange(val) {
      this.pageSize = val;
    },
    handleCurrentChange(val) {
      this.currentPage = val;
    },
    showLogDetails(log) {
      this.currentLog = log;
      this.logDetailsVisible = true;
    },
    // 快速回复相关方法
    selectQuickReply(option) {
      this.customReply = option.text;
    },
    submitReply() {
      if (!this.customReply.trim()) {
        this.$message.warning('回复内容不能为空');
        return;
      }
      
      // 这里添加提交回复的逻辑
      this.$message.success('回复已提交');
      this.logDetailsVisible = false;
      this.customReply = '';
    }
  }
}
</script>

<style scoped>
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.page-title {
  font-size: 24px;
  font-weight: bold;
}

.page-actions {
  display: flex;
}

.page-actions button {
  margin-left: 10px;
}

.expert-mode {
  background-color: #fff;
  border-radius: 4px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  padding: 20px;
  margin-bottom: 20px;
  transition: all 0.3s;
}

.expert-mode:hover {
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.status-tabs {
  display: flex;
  border-bottom: 1px solid #e8e8e8;
  margin-bottom: 20px;
}

.status-tab {
  padding: 10px 20px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

.status-tab.active {
  border-bottom-color: #1890ff;
  color: #1890ff;
  font-weight: bold;
}

.status-content {
  padding: 15px 0;
}

.status-card {
  background-color: #f9f9f9;
  border-radius: 4px;
  padding: 15px;
  margin-bottom: 15px;
}

.status-title {
  font-weight: bold;
  margin-bottom: 10px;
}

.status-details {
  color: #666;
  line-height: 1.5;
}

.logs-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}

.logs-title {
  font-size: 16px;
  font-weight: bold;
}

.logs-actions {
  display: flex;
}

.logs-actions button {
  margin-left: 10px;
}

.log-level {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 10px;
}

.level-info {
  background-color: #90ee90;
}

.level-warning {
  background-color: #ffd700;
}

.level-error {
  background-color: #ff6b6b;
}

.map-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}

.map-title {
  font-size: 16px;
  font-weight: bold;
}

.map-actions {
  display: flex;
}

.map-actions button {
  margin-left: 10px;
}

.map-wrapper {
  height: 400px;
  border: 1px solid #eee;
  border-radius: 4px;
}

.tools-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}

.tools-title {
  font-size: 16px;
  font-weight: bold;
}

.tools-actions {
  display: flex;
}

.tools-actions button {
  margin-left: 10px;
}

.tools-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 15px;
}

.tool-card {
  background-color: #f9f9f9;
  border-radius: 4px;
  padding: 15px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
}

.tool-card:hover {
  background-color: #f0f7ff;
  transform: translateY(-2px);
}

.tool-icon {
  font-size: 24px;
  margin-bottom: 10px;
  color: #1890ff;
}

.tool-name {
  font-weight: bold;
}

.tool-description {
  font-size: 12px;
  color: #666;
  margin-top: 5px;
}

.pagination {
  margin-top: 20px;
  text-align: right;
}

/* 现有样式 */

/* 快速回复样式 */
.quick-reply-section {
  margin-top: 20px;
  border-top: 1px solid #eee;
  padding-top: 20px;
}

.quick-reply-options {
  margin-bottom: 15px;
}

.quick-reply-options .el-button {
  margin-right: 10px;
  margin-bottom: 10px;
}

.log-details .detail-item {
  margin-bottom: 10px;
}

.detail-label {
  font-weight: bold;
  margin-right: 10px;
}
</style>